﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace AvaloniaApplication1.Converters
{
    public class LevelFontConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter== null)
            {
                return null;
            }

            string type = parameter.ToString();
            bool IsConverterSuccess = false;
            int level = -1;
            if (value != null)
            {
                IsConverterSuccess = int.TryParse(value.ToString(), out level);
            }


            switch (type)
            {
                case "FontSize":
                    double defultFontSize = 12;
                    if (value == null)
                    {
                        return defultFontSize;
                    }

                     
                    if (!IsConverterSuccess)
                    {
                        return defultFontSize;
                    }

                    if (level != 0)
                    {
                        return defultFontSize;
                    }

                    return 24;
                case "FontWwight":
                    FontWeight defultFontWeight = FontWeight.Normal;
                     if (value == null)
                    {
                        return defultFontWeight;
                    }
                     
                    if (!IsConverterSuccess)
                    {
                        return defultFontWeight;
                    }

                    if (level != 0)
                    {
                        return defultFontWeight;
                    }

                    return FontWeight.UltraBold;
                    break;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
